package com.hefei.garden.config.redis;

import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author devil
 */
@Component
@RefreshScope
public class GardenJedisPoolConfig {

    private static final String HOST = "127.0.0.1";
    private static final int PORT = 6379;
    private static final String AUTH = null;
    private static final int CONN_AND_READ_WRITE_TIME_OUT = 10000;

    private static class InnerClass {

        private static final JedisPool JEDIS_POOL = new JedisPool(
                getConfig(),
                HOST,
                PORT,
                CONN_AND_READ_WRITE_TIME_OUT,
                AUTH
        );

        private static JedisPoolConfig getConfig() {
            JedisPoolConfig poolConfig = new JedisPoolConfig();
            poolConfig.setMaxTotal(10000);
            poolConfig.setMaxIdle(50);
            poolConfig.setMaxWaitMillis(5 * 1000);
            return poolConfig;
        }
    }

    /**
     * 返回jedisPool实例
     *
     * @return
     */
    public static JedisPool getJedisPool() {
        return InnerClass.JEDIS_POOL;
    }

}